package com.neusoft.yiyang.bed.controller;

import com.neusoft.yiyang.bed.service.BedAllocationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Tag(name = "床位分配接口", description = "负责床位分配、调换等操作")
@RestController
@RequestMapping("/beds")
public class BedAllocationController {

    @Autowired
    private BedAllocationService bedAllocationService;

    @Operation(summary = "分配床位给客户", description = "为指定客户分配床位，可指定结束日期（到期自动释放）")
    @PostMapping("/{customerId}/assign-bed/{bedId}")
    public void assignBedToCustomer(
            @Parameter(description = "客户ID", required = true) @PathVariable Integer customerId,
            @Parameter(description = "床位ID", required = true) @PathVariable Integer bedId,
            @Parameter(description = "床位使用结束日期（可选，格式：yyyy-MM-dd HH:mm:ss）")
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
        bedAllocationService.assignBedToCustomer(customerId, bedId, endDate);
    }

    @Operation(summary = "为客户调换床位", description = "将客户从原床位调换至新床位，可更新使用结束日期")
    @PostMapping("/{customerId}/swap-bed/{oldBedId}/{newBedId}")
    public void swapBedForCustomer(
            @Parameter(description = "客户ID", required = true) @PathVariable Integer customerId,
            @Parameter(description = "原床位ID", required = true) @PathVariable Integer oldBedId,
            @Parameter(description = "新床位ID", required = true) @PathVariable Integer newBedId,
            @Parameter(description = "新床位使用结束日期（可选，格式：yyyy-MM-dd HH:mm:ss）")
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
        bedAllocationService.swapBedForCustomer(customerId, oldBedId, newBedId, endDate);
    }
}